//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#include "OperandRequest.h"

#include <sstream>

#include "Constraint.h"
#include "Log.h"

using namespace std;

namespace Green {

  OperandRequest::OperandRequest(const string& name, uint64 value)
    : Object(), mName(name), mpValueConstraint(nullptr), mApplied(false), mIgnored(false)
  {
    SetValueRequest(value);
  }

  OperandRequest::OperandRequest(const string& name, const string& valueStr)
    : Object(), mName(name), mpValueConstraint(nullptr), mApplied(false), mIgnored(false)
  {
    SetValueRequest(valueStr);
  }

  OperandRequest::OperandRequest(const OperandRequest& rOther)
    : Object(rOther), mName(rOther.mName), mpValueConstraint(nullptr), mApplied(false), mIgnored(false)
  {
    if (nullptr != rOther.mpValueConstraint) {
      mpValueConstraint = rOther.mpValueConstraint->Clone();
    }
  }

  OperandRequest::~OperandRequest()
  {
    delete mpValueConstraint;
  }

  Object* OperandRequest::Clone() const
  {
    return new OperandRequest(*this);
  }

  const std::string OperandRequest::ToString() const
  {
    stringstream out_stream;

    out_stream << Type() << ": " << Name();
    if (nullptr != mpValueConstraint) {
      out_stream << "<=" << mpValueConstraint->ToSimpleString() << endl;
    }

    return out_stream.str();
  }

  void OperandRequest::SetValueRequest(uint64 value)
  {
    if (nullptr != mpValueConstraint) {
      delete mpValueConstraint;
    }

    mpValueConstraint = new ConstraintSet(value);
  }

  void OperandRequest::SetValueRequest(const std::string& valueStr)
  {
    if (nullptr != mpValueConstraint) {
      delete mpValueConstraint;
    }

    mpValueConstraint = new ConstraintSet(valueStr);
  }

}
